package com.liangtian.mdm.material.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liangtian.mdm.material.dao.WlLbUpdateDao;
import com.liangtian.mdm.material.model.WlLbUpdate;
import com.liangtian.mdm.material.service.WlLbUpdateService;

@SuppressWarnings({"unchecked", "rawtypes"})
@Service
public class WlLbUpdateServiceImpl implements WlLbUpdateService {

    @Autowired
    private WlLbUpdateDao wlLbUpdateDao;

    @Override
    public PageInfo wlLbUpdateBgPageLst(Map<String, Object> map) {
        PageInfo<List<WlLbUpdate>> pageInfo = null;
        try {
            Object pNo = map.get("pageNum");
            int pageNum, pageSize;
            // export
            if (pNo != null && !"NaN".equals(pNo)) {
                pageNum = Integer.parseInt(pNo.toString());// 页码
            } else {
                pageNum = 1;
            }
            // pageSize=0时不分页
            pageSize = Integer.parseInt(map.get("limit").toString());// 模型定义页面要显示数据条数
            // 例如
            // 10,20,50,100
            PageHelper.startPage(pageNum, pageSize);// 开始分页标志（当前页，显示条数）
            List<WlLbUpdate> list = wlLbUpdateDao.wlLbUpdateBgPageLst(map);
            pageInfo = new PageInfo(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pageInfo;
    }

    @Override
    public WlLbUpdate getWlLbUpdateById(WlLbUpdate update) {
        return wlLbUpdateDao.getWlLbUpdateById(update);
    }

    @Override
    public void updateWlLbUpdate(WlLbUpdate update) {
		/*if(update.getLbbm().length() == 2){
			wlLbUpdateDao.updateWlLbUpdateShort(update);
		} else {
			wlLbUpdateDao.updateWlLbUpdate(update);
		}*/
        wlLbUpdateDao.updateWlLbUpdate(update);

    }

    @Override
    public int EditByCheckCodeAndModel(WlLbUpdate update) {
        Map<String, Object> map = new HashMap<>();
        map.put("lbbm", update.getLbbm());
        return wlLbUpdateDao.EditByCheckCodeAndModel(map);
    }

    @Override
    public int deleteWlLbUpdateByIdS(Map<String, Object> map) {
        return wlLbUpdateDao.deleteWlLbUpdateByIdS(map);
    }

    @Override
    public PageInfo getWllbUpdateListByCondUpdate(Map<String, Object> map) {
        PageInfo<List<WlLbUpdate>> pageInfo = null;
        try {
            Object pNo = map.get("pageNum");
            int pageNum, pageSize;
            // export
            if (pNo != null && !"NaN".equals(pNo)) {
                pageNum = Integer.parseInt(pNo.toString());// 页码
            } else {
                pageNum = 1;
            }
            // pageSize=0时不分页
            pageSize = Integer.parseInt(map.get("limit").toString());// 模型定义页面要显示数据条数
            // 例如
            // 10,20,50,100
            PageHelper.startPage(pageNum, pageSize);// 开始分页标志（当前页，显示条数）
            List<WlLbUpdate> list = wlLbUpdateDao.getWllbUpdateListByCondUpdate(map);
            pageInfo = new PageInfo(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pageInfo;
    }

    @Override
    public PageInfo wlLbUpdatePageLst(Map<String, Object> map) {
        PageInfo<List<WlLbUpdate>> pageInfo = null;
        try {
            Object pNo = map.get("pageNum");
            int pageNum, pageSize;
            // export
            if (pNo != null && !"NaN".equals(pNo)) {
                pageNum = Integer.parseInt(pNo.toString());// 页码
            } else {
                pageNum = 1;
            }
            // pageSize=0时不分页
            pageSize = Integer.parseInt(map.get("limit").toString());// 模型定义页面要显示数据条数
            // 例如
            // 10,20,50,100
            PageHelper.startPage(pageNum, pageSize);// 开始分页标志（当前页，显示条数）
            List<WlLbUpdate> list = wlLbUpdateDao.wlLbUpdatePageLst(map);
            pageInfo = new PageInfo(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pageInfo;
    }

    @Override
    public List<WlLbUpdate> getWllbUpdateListByCond(Map<String, Object> cond) {
        return wlLbUpdateDao.getWllbUpdateListByCond(cond);
    }

    @Override
    public int updateWllbByUpdate(Map<String, Object> cond) {
        return wlLbUpdateDao.updateWllbByUpdate(cond);
    }

    @Override
    public int updateWllbStateByCond(Map<String, Object> cond) {
        return wlLbUpdateDao.updateWllbStateByCond(cond);
    }

    @Override
    public int checkNameUpdate(WlLbUpdate update) {
        Map<String, Object> map = new HashMap<>();
        map.put("lbmc", update.getLbmc());
        map.put("lbbm", update.getLbbm());
        return wlLbUpdateDao.checkNameUpdate(map);
    }

    @Override
    public void insertWlLbUpdate(WlLbUpdate update) {
        wlLbUpdateDao.insertWlLbUpdate(update);
    }

}
